package com.medvalley.tcm.controller;

import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.service.impl.MindQuestionnaireService;
import com.medvalley.tcm.vo.inputvo.MindQuestionnaireInputVo;
import com.medvalley.tcm.vo.outputvo.MindQuestionnaireOutputVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/mind")
@Api("精神问卷调查")
public class MindQuestionnaireController extends BaseController {

    @Autowired
    private MindQuestionnaireService mindQuestionnaireService;

    @ApiOperation("提交用户信息")
    @PostMapping("/begin")
    public Result begin(@ModelAttribute MindQuestionnaireInputVo userInfo) {
        long id = mindQuestionnaireService.addUser(userInfo);
        return success(id);
    }

    @PostMapping("/submit")
    @ApiOperation("提交答案")
    public Result submit(@ModelAttribute MindQuestionnaireInputVo answer, HttpServletRequest request) {
        long userId = getUserId(request);
        MindQuestionnaireOutputVo outputVo = mindQuestionnaireService.submitAnswer(answer, userId);
        return success(outputVo);
    }

    @PostMapping("/list_by_phone")
    @ApiOperation("我的记录")
    public Result list(@RequestParam String phone, @RequestParam int type) {
        List<MindQuestionnaireOutputVo> outputVos = mindQuestionnaireService.listByPhone(phone, type);
        return success(outputVos);
    }

    @PostMapping("/detail_by_id")
    @ApiOperation("我的记录详情")
    public Result detail(@RequestParam long id) {
        MindQuestionnaireOutputVo m = mindQuestionnaireService.detailById(id);
        return success(m);
    }
}
